package blue.commons.dao;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.XmlElement;

import java.util.Date;
import java.util.Properties;
import java.util.Set;

/**
 * Created by jianshan on 2017/12/12.
 */

public class MyCommentGenerator implements CommentGenerator {

    private static final String defaultDateTimePattern = "yyyy-MM-dd HH:mm:ss";

    private static final String classTopComment="/**\n" +
            " * Generated by 孟玉\n" +
            " * 致力于更好的开发\n" +
            " * %s\n" +
            " */";

    private static final String fieldComment="/**\n" +
            "     * %s\n" +
            "     */";


    public void addConfigurationProperties(Properties properties) {

    }

    public MyCommentGenerator() {
    }

    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (StringUtils.isNotBlank(introspectedColumn.getRemarks())) {
            String remark=String.format(fieldComment,introspectedColumn.getRemarks());
            field.addJavaDocLine(remark);
        }
    }

    public void addFieldComment(Field field, IntrospectedTable introspectedTable) {

    }

    public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {

//        String remark=String.format(String.format(classTopComment, dateHuman(new Date())));
//
//        topLevelClass.addJavaDocLine(remark);
    }

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
    }

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean b) {

    }

    public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {

    }

    public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {

    }

    public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {

    }

    public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {

    }

    public void addJavaFileComment(CompilationUnit compilationUnit) {

    }

    public void addComment(XmlElement xmlElement) {

    }

    public void addRootComment(XmlElement xmlElement) {

    }

    public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> set) {

    }

    public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> set) {

    }

    public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> set) {

    }

    public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> set) {

    }

    public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> set) {

    }

//    public static String dateHuman(Date date){
//        if(date==null){
//            return StringUtils.EMPTY;
//        }
//
//        return DateFormatUtils.format(date,defaultDateTimePattern);
//
//    }

}
